package com.suray.rgv.son.data;

import com.suray.basic.wcs.utils.typedef.Byte;
import com.suray.basic.wcs.utils.typedef.Word;

public class ModbusReadMessage extends ModbusBaseMessage {

    public ModbusReadMessage() {
        super("子车modbus读", true);

        baseDatas.add(new Byte("slaveAddr", "从机地址"));
        baseDatas.add(new Byte("funcCode", "功能代码"));
        baseDatas.add(new Word("startAddr", "数据起始地址"));
        baseDatas.add(new Word("dataLength", "寄存器个数"));
//        baseDatas.add(new Byte("dataByteNum", "寄存器对应的字节数量"));

        setValue("slaveAddr", 1);
        setValue("funcCode", 0x4);

        baseDatas.add(new Word("crc", "crc校验"));

    }

    public void setMessageInfo(int startAddress, int readAddressSize) {
        setValue("startAddr", startAddress);
        setValue("dataLength", readAddressSize);
//        setValue("dataByteNum", readAddressSize * 2);
        setValue("crc", calcCrc(makeMessage()));
    }

    public int getSlaveAddr() {
        return getValue("slaveAddr");
    }

    public int getStartAddr() {
        return getValue("startAddr");
    }

    public int getDataLength() {
        return getValue("dataLength");
    }

    public int getCrc() {
        return getValue("crc");
    }
}
